package com.hushao.aimi.repository;

import com.hushao.aimi.entity.AimiRecommend;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface RecommendRepository extends JpaRepository<AimiRecommend,Integer> {

    @Query(value = "SELECT r.`recommend_id` ,r.`product_id` ,r.`recommend_code` ,r.`recommend_image` ,r.`recommend_title` ,r.`sort_order`,r.`recommend_status` ,r.`create_time` ,r.`update_time` ,r.`comment`  ,`product_code`, p.`name`   FROM `aimi_recommend` r LEFT JOIN `aimi_product` p on r.`product_id` =p.`id` WHERE  p.`product_code` LIKE :productCode ",
            countQuery = "select count(*) from `aimi_recommend` r left join `aimi_product` p on r.`product_id` =p.`id` WHERE  p.`product_code` LIKE :productCode",
            nativeQuery = true)
    Page<Object> listByProductCodeLike(@Param("productCode") String productCode, Pageable pageable);
}
